﻿using DMC.Core.Models.Dto;
using DMC.Core.Models.Queries;
using DMC.Core.Models.VO;
using DMC.Core.Providers;
using MiniFox.Components;
using MiniFox.Infrastructure;
using MiniFox.Platform.Applications;
using MiniFox.Platform.Applications.Auth;
using MiniFox.Platform.Exceptions;

namespace DMC.Core.Services.Impls
{
    [AutoResolve]
    public class ExcelImportService : ApiServiceBase, IExcelImportService
    {
        public ExcelImportService(SystemPrincipal principal) : base(principal)
        {
        }
        [AutoWired]
        protected IExcelImportProvider Provider { get; set; }

        public ResultObject<IEnumerable<ExcelImportVo>> Query(PagedQueryObject<ExcelImportQuery> request)
        {
            return this.Provider.Query(request);
        }

        public ExcelImportVo Item(string name)
        {
            return this.Provider.Item(name);
        }

        public ExcelImportVo Update(ExcelImportDto dto)
        {
            if (this.Provider.Update(dto))
                return this.Provider.Item(dto.Name);
            return null;
        }

        public void Remove(string name)
        {
            if (this.Provider.Remove(name))
                throw new PlatformException("ERR_OperateFail");
        }

        public ExcelImportVo Create(ExcelImportDto dto)
        {
            if (this.Provider.Create(dto))
                return this.Provider.Item(dto.Name);
            return null;
        }
    }
}
